using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Box2D.XNA;
using Microsoft.Xna.Framework;
using Spinning.Spinning.Unitity;

namespace Spinning.Spinning.Entity
{
    class WindowBound : BaseEntity
    {

        protected Bound top, left, right, down;

        public WindowBound()
        {
            top = new Bound();
            left = new Bound();
            right = new Bound();
            down = new Bound();

            top.Size = new Vector2(Constants.Window_Width, 2);
            down.Size = new Vector2(Constants.Window_Width, 2);
            right.Size = new Vector2(2, Constants.Window_Height);
            left.Size = new Vector2(2, Constants.Window_Height);

            Attach(top);
            Attach(left);
            Attach(right);
            Attach(down);

        }

        public void OnCreatBound(World world)
        {
            top.OnCreatBound(world);
            down.OnCreatBound(world);
            left.OnCreatBound(world);
            right.OnCreatBound(world);
        }

        protected override void UpdateSelf(GameTime gameTime)
        {
            base.UpdateSelf(gameTime);
            setPosition(this.Position);
        }

        protected void setPosition(Vector2 pos)
        {
            top.Position = new Vector2(Constants.Window_Width / 2, 0) + pos;
            down.Position = new Vector2(Constants.Window_Width / 2, Constants.Window_Height) + pos;
            left.Position = new Vector2(0, Constants.Window_Height / 2) + pos;
            right.Position = new Vector2(Constants.Window_Width, Constants.Window_Height / 2) + pos;
        }

        private Body creatWall(World world, Vector2 size, Vector2 poistion)
        {
            BodyDef bd = new BodyDef();
            bd.type = BodyType.Static;
            Body body = world.CreateBody(bd);
            FixtureDef fd = new FixtureDef();
            PolygonShape ps = new PolygonShape();
            ps.SetAsBox(size.X / Constants.MeterToPixal, size.Y / Constants.MeterToPixal);
            fd.shape = ps;
            Fixture f = body.CreateFixture(fd);
            Vector2 pos = Functional.Vector2InWorld(poistion);
            body.SetTransform(pos, 0);
            Filter filter = new Filter();
            filter.categoryBits = (ushort)Constants.CategoryBitsWall;
            filter.maskBits = (ushort)Constants.MaskBitsWall;
            f.SetFilterData(ref filter);
            return body;
        }
    }
}
